package com.dkd.day20250616;

public class SolutionlongestCommonPrefix {
    public static void main(String[] args) {
        String [] strs = {"abca","abc","abca","abc","abcc"};
        System.out.println(longestCommonPrefix(strs));
    }

    public static String longestCommonPrefix (String[] strs) {
        // write code here
        //非空判断
        if(strs == null || strs.length == 0) return "";
        for (int i = 0; i < strs[0].length(); i++) {
            char c = strs[0].charAt(i);
            for (int j = 1; j < strs.length; j++) {
                if (strs[j].length()==i ||c != strs[j].charAt(i)) {
                    return strs[0].substring(0, i);
                }
            }
        }
        return strs[0];
    }
}
